<?php
    header("Content-type:text/html;charset=utf-8");
    require('./conn/mysql.php');
   
    $username = $_POST['username'];
    $password = $_POST['password'];

    if(!$username || !$password) die(write(0, '用户名和密码不能为空!'));

    try{
        $password = md5($password);
        $sql = "select * from `sys_user` where (`user_mobile` = '$username' or `user_email` = '$username' or `user_account` = '$username') and `user_pwd` = '$password' and `del_flag` = '1'";
        $res = mysql::getRow($sql);
        if(!$res) die(write(0, '登录失败,用户不存在或密码不正确!'));
        $time = date('Y-m-d H:i:s', time());
        $user_id = $res['user_id'];
        $sql = "update `sys_user` set `user_last_login` = '$time' where `user_id` = $user_id";
        mysql::query($sql);
        unset($res['user_idcard']);
        unset($res['user_pwd']);
        echo write(1, '登录成功', $res);
    }catch(\Throwable $t){
        echo write(0, ''.$t);
    }finally{
         mysql::close();
    }
    function write($code, $msg, $data=[]){
        $rd = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        );
        return json_encode($rd, JSON_UNESCAPED_UNICODE);
    }
?>